package fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.projectmoudle_two.R;

import java.util.ArrayList;
import java.util.List;

import view.SmoothScrollListview;

/**
 * Created by eyesee on 2017/5/19.
 */

public class SmootScrollListviewFragment extends BaseFragment {

    private List<String> mList;
    private SmoothScrollListview mListview;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_listscroll, null);
        initData();
        mListview = ((SmoothScrollListview) view.findViewById(R.id.listview));
        mListview.setAdapter(new Adapter());
        mListview.setScrollDuration(200);
        return view;
    }

    private void initData() {
        mList = new ArrayList<>();
        for (int i = 0; i <50 ; i++) {
            mList.add(i+"号");
        }
    }

    public class Adapter extends BaseAdapter{

        @Override
        public int getCount() {
            return mList==null?0:mList.size();
        }

        @Override
        public Object getItem(int position) {
            return mList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView ==null){
                holder = new ViewHolder();
                convertView = View.inflate(mContext,R.layout.listscroll_item,null);
                holder.mTextView = (TextView) convertView.findViewById(R.id.tv_item);
                convertView.setTag(holder);
            }else {
                holder=((ViewHolder) convertView.getTag());
            }

            holder.mTextView.setText(mList.get(position));

            return convertView;
        }
    }
    class ViewHolder{
        TextView mTextView;
    }
}
